/**
  ******************************************************************************
  * @file    led.c 
  * @author  houyannian
  * @version V1.0
  * @date    2022-08-14
  * @brief   led program body
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/

#include "led.h"

//LED配置函数，外接LED为高电平，这里配置管脚初始状态为输出高电平，设置输出速率为最低完全满足设计要求
void led_init(void)
{
    //使能端口始终，默认情况为了降低功耗始终在关闭状态
    RCC_AHB1PeriphClockCmd(LED_RED_COLCK | LED_GREEN_COLCK | LED_BLUE_COLCK, ENABLE);

    GPIO_InitTypeDef GPIO_InitStruct;
    
    //配置管脚为推挽上拉输出模式
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStruct.GPIO_Speed = GPIO_Low_Speed;

    GPIO_InitStruct.GPIO_Pin = LED_BLUE_PIN;
    GPIO_Init(LED_BLUE_PORT, &GPIO_InitStruct);

    GPIO_InitStruct.GPIO_Pin = LED_GREEN_PIN;
    GPIO_Init(LED_GREEN_PORT, &GPIO_InitStruct);

    GPIO_InitStruct.GPIO_Pin = LED_RED_PIN;
    GPIO_Init(LED_RED_PORT, &GPIO_InitStruct);

    //设置3个LED管脚为高电平
    GPIO_SetBits(LED_BLUE_PORT, LED_BLUE_PIN);
    GPIO_SetBits(LED_GREEN_PORT, LED_GREEN_PIN);
    GPIO_SetBits(LED_RED_PORT, LED_RED_PIN);
}


